package com.suneast.suneaststore.modules.personal.order.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.suneast.suneaststore.R;
import com.suneast.suneaststore.bean.personal.order.ListBean;
import com.suneast.suneaststore.modules.personal.order.OrderHandler;

abstract class BaseViewHolder extends RecyclerView.ViewHolder {
    protected int status;
    protected int listType;
    protected Button[] buttons = new Button[2]; // 0 left 1 right

    final int getStatus() {
        return status;
    }

    BaseViewHolder(View itemView, int status, int listType) {
        super(itemView);
        this.status = status;
        this.listType = listType;
    }

    abstract void updateData(ListBean.Order order);

    @FunctionalInterface
    protected interface ButtonConstructor {
        void construct(Button[] buttons, int status);
    }

    protected static ButtonConstructor []constructors = new ButtonConstructor[] {
            (buttons, status)->{
                switch (status) {
                    case OrderHandler.ORDER_UNPAID:
                        buttons[0].setText(R.string.pay_order);
                        buttons[1].setText(R.string.cancel_order);
                        buttons[0].setVisibility(View.VISIBLE);
                        break;
                    case OrderHandler.ORDER_TOBE_DELIVERED:
                        buttons[1].setText(R.string.order_reminder);
                        break;
                    case OrderHandler.ORDER_TOBE_RECEIVED:
                        buttons[1].setText(R.string.receive_confirm);
                        break;
                    case OrderHandler.ORDER_TOBE_COMMENTED:
                        buttons[1].setText(R.string.comment_order);
                        break;
                    case OrderHandler.ORDER_AFTER_SALES:
                        buttons[1].setText(R.string.req_after_sale);
                        break;
                    case OrderHandler.ORDER_CANCELED:
                        buttons[1].setText(R.string.delete_order);
                        break;
                    default:
                        break;
                }
                buttons[1].setVisibility(View.VISIBLE);
            },
            (buttons, status)->{
                switch (status) {
                    case OrderHandler.ORDER_TOBE_DELIVERED:
                        buttons[1].setText(R.string.order_to_deliver);
                        buttons[1].setVisibility(View.VISIBLE);
                        break;
                }
            }
    };
}